/*
 * @Date: 2025-06-13 11:12:23
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-08-01 17:59:17
 * @FilePath: \corpus\src\pages\Foundation\city.tsx
 */
/*
 * @Date: 2025-06-13 11:12:23
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-06-17 15:31:47
 * @FilePath: \corpus\src\pages\Home\index.tsx
 */
import React, { useEffect, useState } from 'react';

import type { ListItem } from '@/services/ant-design-pro/typings';
import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
import { history, useModel } from '@umijs/max';
import { Col, Pagination, Row } from 'antd';
import styles from './index.less';
import List from '../Home/component/List';
import EditCorpus from '../Home/EditCorpus';
import EditAngent from '../Home/EditAngent';
import hooks from '../Home/hooks/useHooks';
const Home: React.FC = () => {
  const { getData, data, setType, setDetail, setCorpuVisible, formCorpus, editKnowledgeContent } =
    hooks.useContainer();
  useEffect(() => {
    getData.run({ current: 1, pageSize: 10, type: 'jc' });
  }, []);

  const { getRole } = useModel('useUser', (model) => {
    return {
      getRole: model.getRole,
    };
  });

  const [value, setValue] = useState('');

  const AddContent = () => {
    return (
      <>
        <div
          onClick={() => {
            formCorpus.resetFields();
            setType('jc');
            setDetail({});
            setCorpuVisible(true);
          }}
          className={styles.wrapperAddContent}
        >
          <div
            style={{
              width: '100%',
              display: 'flex',
              flexDirection: 'column',
              alignItems: 'center',
            }}
          >
            <div className={styles.wrapperAddContentCon}>
              <PlusOutlined style={{ color: '#1d498b', fontSize: '20.0px' }} />
            </div>
            <div
              style={{
                color: '#1d498b',
                textAlign: 'center',
                marginTop: '10.0px',
                fontSize: '20.0px',
              }}
            >
              新增
            </div>
          </div>
        </div>
      </>
    );
  };

  const handleUpContent = (val: Record<any, any>) => {
    editKnowledgeContent.run({ ...val });
  };
  return (
    <div className={styles.wrapperContent}>
      <div className={styles.titleContent}>
        <div className={styles.knowledgeContent}>城市治理基础语料库管理</div>
        <div className={styles.knowledgeSearch}>
          <div className={styles.knowledge}>
            <input
              onInput={(val: any) => {
                const value = val.target.value;
                setValue(value);
              }}
              placeholder="请输入内容"
            />
            <div
              onClick={() => {
                getData.run({ current: 1, pageSize: 10, name: value, type: 'cs' });
              }}
              className={styles.search}
            >
              <SearchOutlined color="#ffffff" style={{ color: '#FFFFFF', fontSize: '20.0px' }} />
            </div>
          </div>
        </div>
      </div>

      <Row gutter={20} className={styles.wrapper}>
        {getRole('jcknowledge:upload') && (
          <Col md={24} lg={12} xl={8} xxl={6} className={styles.addWrap}>
            <AddContent />
          </Col>
        )}
        {data?.data?.map((item: ListItem, index: number) => {
          return (
            <List
              handleClick={(val: any) => {
                history.push(
                  {
                    pathname: '/knowledge/file5',
                  },
                  { knowledgeId: val.id, type: val.type },
                );
              }}
              handleUp={handleUpContent}
              item={item}
              key={index}
            />
          );
        })}
      </Row>
      <div className={styles.footer}>
        <Pagination
          size="small"
          showQuickJumper
          defaultCurrent={1}
          total={data?.total ?? 0}
          onChange={(val) => {
            getData.run({ current: val, pageSize: 10, name: value, type: 'jc' });
          }}
        />
      </div>

      <EditCorpus />

      <EditAngent />
    </div>
  );
};

export default () => {
  return (
    <hooks.Provider>
      <Home />
    </hooks.Provider>
  );
};
